package com.wteam.dragon.system.util;

import cn.hutool.core.util.PageUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 将列表分页输出
 * @Author 陈晓辉
 * @Date 2020/5/25 9:57
 */
@Getter
@Setter
public class ListPageUtil<T> extends PageUtil{

    private static final long serialVersionUID = 1597640517615975332L;

    private long total;

    private List<T> records;

    private long current;

    private long size;

    public ListPageUtil(List<T> list, Page<T> page) {
        this.total = list.size();
        this.current = page.getCurrent();
        this.size = page.getSize();
        long skip = (current - 1) * size;
        this.records = list.stream().skip(skip).limit(size).collect(Collectors.toList());
    }
}
